package cn.bankAutoOffice.controller;

import cn.bankAutoOffice.bean.entity.Performance;
import cn.bankAutoOffice.service.PerformanceService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class PerformanceController {
    @Resource
    private PerformanceService performanceService;
//查看所有人的绩效完成与否
    @RequestMapping("/performance")
    public List performance(){
        List<Performance> set = performanceService.set();
        //System.out.println(set.get(0).getOneSelfSales());
        for (int i = 0; i <set.size() ; i++) {
            if (set.get(i).getOneSelfSales()>set.get(i).getDistriButedSales())
            {
                performanceService.ins(set.get(i).getId());
            } }
        return performanceService.set();
}


//由上级分配给下级需要达到的绩效
    @RequestMapping("/setperformance")
    public String setperformance(@RequestParam("id")int id,
                                 @RequestParam("distributedsales")int distributedsales){
        if (performanceService.setperformance(id, distributedsales)!=1){
            return "设置失败";
        }
        return "修改成功";
    }

    //个人设置自己目前绩效
    @RequestMapping("/setoneselfsales")
    public String setoneselfsales(@RequestParam("id")int id,
                                 @RequestParam("oneselfsales")int oneselfsales){
        if (performanceService.setoneselfsales(id, oneselfsales)!=1){
            return "设置失败";
        }
        return "修改成功";
    }

    //通过empcode模糊查询
    @RequestMapping("/blur")
    public List blur(@RequestParam("empCode")String empCode){
        List blur = performanceService.blur(empCode);

        return blur;
    }

}
